<?php
	namespace Common\Logic;
	use Common\Model\OperatorsModel;
	class MemberLogic extends OperatorsModel{
		/*
		* Function:		getMemberList
		* Description:	用户列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getMemberList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getMemberFilter($filter);
			return $this->where($conditon)->order('id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getMemberFilter
		* Description:	用户列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getMemberFilter($filter = ''){
			$conditon = array();
			if(!empty($filter['login_name'])){
				$conditon['login_name'] = $filter['login_name'];
			}
			if(!empty($filter['real_name'])){
				$conditon['real_name'] = array('like',$filter['real_name'].'%');
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getMemberCount
		* Description:	用户列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getMemberCount($filter = ''){
			$conditon = $this->getMemberFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		getMemberByUserName
		* Description:  获取会员信息——通过login_name
		* Params:		$login_name string 用户名，$id int 用户id
		*/
		public function getMemberByUserName($login_name = '',$id = ''){
			$conditon = array();
			if(!empty($login_name)){
				$conditon['login_name'] = $login_name;
			}
			if(!empty($id)){
				$conditon['id'] = array('neq',$id);
			}
			return $this->where($conditon)->find();
		}
		
		/*
		* Function:		getMemberByRealName
		* Description:  获取会员信息——通过real_name
		* Params:		$real_name string 姓名，$id int 用户id
		*/
		public function getMemberByRealName($real_name,$id = ''){
			$conditon = array();
			if(!empty($real_name)){
				$conditon['real_name'] = $real_name;
			}
			if(!empty($id)){
				$conditon['id'] = array('neq',$id);
			}
			return $this->where($conditon)->find();
		}
		
		/*
		* Function:		addMember
		* Description:	增加用户
		* @param:		$data array 增加的数组
		*/
		public function addMember($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getMemberInfo
		* Description:	获取用户列表信息 by row
		* @param:		$id int ID
		*/
		public function getMemberInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		getMemberAllList
		* Description:	获取用户列表信息 by row
		* @param:		$id int ID
		*/
		public function getMemberRoleList($role = ''){
			$conditon = array();
			if(!empty($role)){
				$conditon['priv'] = $role;
			}
			return $this->where($conditon)->select();
		}
		
		/*
		* Function:		updateMember
		* Description:	更新用户
		* @param:		$data array 更新的数组
		*/
		public function updateMember($data){
			return $this->save($data);
		}
		
		/*
		* Function:		checkPasswdIsExist
		* Description:	检测密码是否存在
		* @param:		$login_pass string 登录密码 $id int 用户id
		*/
		public function checkPasswdIsExist($login_pass,$id){
			return $this->where(array('login_pass'=>$login_pass,'id'=>$id))->find();
		}
		
		/*
		* Function:		getMemberListByDepartment
		* Description:	获取用户列表信息 by list
		* @param:		$id int ID
		*/
		public function getMemberListByDepartment($department_id = ''){
			$conditon = array();
			$conditon['status'] = 1;
			if(!empty($department_id)){
				$conditon['department_id'] = $department_id;
			}
			return $this->where($conditon)->select();
		}
	}
?>